package com.zky.gulimall.order.controller;

import com.zky.gulimall.order.entity.OrderEntity;
import com.zky.gulimall.order.entity.OrderItemEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @Description test
 * @Author 张开源
 * @Date 2022/12/8 17:41
 * @Version 1.0
 **/
@RestController
@Slf4j
public class TestController {
    @Autowired
    private AmqpAdmin admin;
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMessage")
    public Boolean sendMessage() {

        for (int i = 0; i < 30; i++) {
            if (i % 3 == 0) {
                Map<String, String> map = new HashMap<>();
                map.put("11", "消息收到了");
                map.put("key", "消息收到了11");
                map.put("1434", "test");
                map.put("4334", "fdfddffdfd");
                rabbitTemplate.convertAndSend("zky-java-exchange", "hello.java", map,new CorrelationData(UUID.randomUUID().toString()));
                log.warn("sendMessage,map {} 发送成功", map);
            } else if (i % 3 == 1) {
                OrderItemEntity orderItemEntity = new OrderItemEntity();
                orderItemEntity.setOrderId(6L);
                orderItemEntity.setSkuId(9L);
                orderItemEntity.setSpuBrand("rerertr");
                rabbitTemplate.convertAndSend("zky-java-exchange", "hello.java", orderItemEntity,new CorrelationData(UUID.randomUUID().toString()));

            } else {
                OrderEntity orderEntity = new OrderEntity();
                orderEntity.setOrderSn("fdfdfd");
                orderEntity.setBillType(9);
                orderEntity.setId(9L);
                rabbitTemplate.convertAndSend("zky-java-exchange", "hello.java", orderEntity,new CorrelationData(UUID.randomUUID().toString()));
            }
        }
        return true;
    }
}
